#
# -= Makefile for application =-
#
# Note:
# . "make config" must be done for initial routines.
#
# Usage:
# . Change the ROOT definition, if necessary;
#   Make it point to the root of the software tree.
#

# Destination to the root of software tree
ROOT = ../../../../../..

# output file name
OUT = bloader3
SEE_OUT = see_bloader3
SEELIB = libblsee_3606

all :
	${MAKE} release
	${MAKE} -f Makefile.cmd all
	cp -f ${ROOT}/inc/modules_temp.h ${ROOT}/inc/modules.h
	cp -f ${ROOT}/inc/sys_parameters_temp.h ${ROOT}/inc/sys_parameters.h

rebuild_all :	
	${MAKE} see
	${MAKE} config
	${MAKE} sdk
	${MAKE} new
	${MAKE} all

rebuild_3606_S :	
	${MAKE} see_3606_S
	${MAKE} sdk_3606_S
	${MAKE} config_3606_S
	${MAKE} new
	${MAKE} all
	
path:	
	./getpath.sh
	

config : sys_config.h compiler.def 
	cp -f ${ROOT}/inc/modules.h ${ROOT}/inc/modules_temp.h
	cp -f ${ROOT}/inc/sys_parameters.h ${ROOT}/inc/sys_parameters_temp.h
	cp -f modules.h ${ROOT}/inc
	cp -f sys_config.h ${ROOT}/inc   
	cp -f sys_parameters.h ${ROOT}/inc
	cp -f compiler.def ${ROOT}/src/compiler.def

config_logo : config
	echo -e "\n M3606_SECURE_ENABLE=1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -DM3606_SECURE_ENABLE" >> ${ROOT}/src/compiler.def

config_3606_S : config
	echo -e "\n M3606_SECURE_ENABLE=1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -DM3606_SECURE_ENABLE" >> ${ROOT}/src/compiler.def	
	echo -e "\n _FIRMWARE_SIGN_ENABLE=1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -D_FIRMWARE_SIGN_ENABLE" >> ${ROOT}/src/compiler.def

config_m3603_02v01:config
	echo -e "\n_M3603_02V01_ = 1" >> ${ROOT}/src/compiler.def
	echo "DEFS += -D_M3603_02V01_" >> ${ROOT}/src/compiler.def

clean :
	${MAKE} -f Makefile.cmd clean

new :
	${MAKE} -f Makefile.cmd new

release :
	${MAKE} -f Makefile.cmd release

	
# Link file
link :
	${LD} ${LDFLAGS} ${NEED} -o ${OUT}.out -Map ${OUT}.map \
	  -T lscript.ld libslot.a  -lbl libboot.a -lbl ${LIB} libstandby.a lib7zip.a liblog.a -lc -lgcc -le
	${OBJCOPY} -O binary ${OUT}.out ${OUT}.abs
	./bmerger.exe ${OUT}.abs boot.cfg 128 384
	${OBJDUMP} -D ${OUT}.out > ${OUT}.dis
ifdef _FIRMWARE_SIGN_ENABLE
	cp ${OUT}.abs ../prj/app/demo/combo/sabbat_dual/${OUT}_3606_signed.abs    
else
	cp ${OUT}.abs ../prj/app/demo/combo/sabbat_dual/${OUT}_3606_logo.abs    
endif


# Link file
see_link :
	${LD} ${LDFLAGS} -o ${SEE_OUT}.out -Map ${SEE_OUT}.map \
	  -T see_ldscript.ld ${LIB} $(DDK_BLSDK_DIR)/${SEELIB}.a liblog.a\
	    -lm -lgcc -lc -le
	${OBJCOPY} -O binary ${SEE_OUT}.out ${SEE_OUT}.abs
	${OBJCOPY} -I binary  -B mips -O elf32-tradlittlemips ${SEE_OUT}.abs ${SEE_OUT}.o	
	

cleanld :
	rm -f ${OUT}.out ${OUT}.map ${OUT}.dis libbl.a

sdk:
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_36f_os ;
	
sdk_3606_S:
	cp -f ${ROOT}/inc/modules.h ${ROOT}/inc/modules_temp.h
	cp -f ${ROOT}/inc/sys_parameters.h ${ROOT}/inc/sys_parameters_temp.h
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_3606_S ;	
	cp -f ${ROOT}/inc/modules_temp.h ${ROOT}/inc/modules.h
	cp -f ${ROOT}/inc/sys_parameters_temp.h ${ROOT}/inc/sys_parameters.h

see:
	cp -f ${ROOT}/inc/modules.h ${ROOT}/inc/modules_temp.h
	cp -f ${ROOT}/inc/sys_parameters.h ${ROOT}/inc/sys_parameters_temp.h
	cd ${ROOT}/src/boot/see36f; \
	${MAKE} config_dual; ${MAKE} see_new; ${MAKE} see 
	cp -f ${ROOT}/inc/modules_temp.h ${ROOT}/inc/modules.h
	cp -f ${ROOT}/inc/sys_parameters_temp.h ${ROOT}/inc/sys_parameters.h

see_3606_S:
	cp -f ${ROOT}/inc/modules.h ${ROOT}/inc/modules_temp.h
	cp -f ${ROOT}/inc/sys_parameters.h ${ROOT}/inc/sys_parameters_temp.h
	cd ${ROOT}/src/boot/see36f; \
	${MAKE} config_3606_S; ${MAKE} see_new; ${MAKE} see 
	cp -f ${ROOT}/inc/modules_temp.h ${ROOT}/inc/modules.h
	cp -f ${ROOT}/inc/sys_parameters_temp.h ${ROOT}/inc/sys_parameters.h


dis:
	sde-objdump -D ${OUT}.out > ${OUT}.dis
